The Sample Storage Shim and UT driver folder contains the sample code for a USB Shim and Unittable driver for a Mass Storage Block Device
Description
The USBSampleStorage demonstrates the use of the Mac OS USB to create a class driver for a storage class device. This sample includes the implementation of a compatibility shim in which an ndrv is installed into the device unit table to handle IO requests by the Mac OS to the class driver.
Building the Code
This sample was built using the Metrowerks CodeWarrior Pro 2, IDE v2.1 environment and the Mac OS USB DDK v1.0.1. Also required, is the Universal Interfaces and Libraries 3.1.
To rebuild the project, first place the USBStorageClassDriver folder into the USBDDK:Examples: folder. The project file assumes specific access paths that are project specific. The resulting class driver, USBStorageClassDriver, along with the associated shim file, USBStorageClassShim, are built into the USBDDK:Extensions-MCWBuilt: folder.
You will need to modify the constants defined in the
File: SampleStorageDeviceID.h
in order to build the project. Set the values as appropriate for your device.
Notes
Some quick notes on the implementation of this sample
1. The Shim is loaded by the USB expert even before the init parade because its file creator is 'usbs' and its file type is 'ndrv'. When the expert finds this file, it looks for the exported symbol "USBShim", and calls the routine. You'll notice that the shim installs a DeviceNotification proc so that it will be called upon the kNotifyAddDevice/Interface, and kNotifyRemoveDevice/Interface events.
2. In the file StorageClassShim.c, you will note that in the function call GiveTimeSecondaryInterrupt, there is a call to SystemTask. As per Inside Macintosh, there are many calls which cannot be made at Interrupt time. SystemTask is one of these calls. In the source code file, this function has been commented out since in some cases, it will crash the system. It happens that this code did function for a specific driver from which this source code is derived. The use of SystemTask in this way is NOT SUPPORTED!!
3. We are working on a more current sample to demonstrate how a USB Shim driver correctly handles a media removal event, whether the media was manually ejected or the USB device was hot unplugged. The correct behavior is for the shim to halt all task level processing and require that the media be re-inserted/re-connected. This is similar to what happens when one removes the CD-ROM bay from a G3 PowerBook while a CD-ROM is currently mounted from the drive.
Bug Reports:
If you find any bugs, please send them to "usb@isg.apple.com" and include "Attn: Rich Kubota" and I will try to address them.
Questions:
For any questions which you may have with this sample or with Mac OS USB, please submit them to either the Mac OS USB mailing list, usb@apple.com, or to Worldwide Macintosh Developer Technical Support (WWDTS), dts@apple.com. If you are not familiar with the recent changes to the WWDTS support plans, please check them out at the Developer Programs web page,
<http://developer.apple.com/programs/>
To subscribe to the Mac OS USB Developer mailing list, send an email to usb@isg.apple.com with the email subject set to "subscribe".